<template>
    <van-nav-bar title="添加收货地址" left-text="" left-arrow @click-left="goBack" />
    <van-address-edit :area-list="areaList" show-set-default :area-columns-placeholder="['请选择', '请选择', '请选择']"
        @save="onSave" />

</template>

<script setup>
import { areaList } from '@vant/area-data';
const { proxy } = getCurrentInstance()
const goBack = () => { proxy.$router.go(-1) }
const LoginUser = reactive(proxy.$cookies.get('LoginUser') ?? {})
const onSave = async (val) => {
    let data = {
        busid: LoginUser.id,
        consignee: val.name,
        mobile: val.tel,
        status: val.isDefault == true ? '1' : '0',
        address: val.addressDetail,
        code: val.areaCode
    }
    let result = await Api.AddressAdd(data)
    if (result.code == 1) 
    {
        success({
            message: result.msg,
            onClose: () => {
                goBack();
            }
        });
    }
    else 
    {
        error(result.msg);
    }
}
</script>
